package org.hot100_6.leetcode53;

public class Solution {
    public int findMin(int[] nums) {

        int n = nums.length;
        int left = 0;
        int right = n - 1;

        while (left <= right) {
            int mid = (left + right) >>> 1;
            if (nums[left] <= nums[right]) {
                left = mid;
            } else {
                right = mid - 1;
            }
        }

        return left;
    }

    public int findMin2(int[] nums) {
        int n = nums.length;
        int left = 0;
        int right = n - 1;
        if (nums[left]<nums[right]){
            return left;
        }

        while (left < right) {

            int mid = (left+right)>>>1;
            if (nums[left]<nums[mid]){
                left = mid+1;
            }else{
                right = mid;
            }
        }
        return nums[left];
    }

}
